﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Unscrambler.Data;
using System.Xml.Linq;

namespace UnscramblerUnitTests.Data
{
    [TestFixture]
    public class RandomWordChooserTests
    {
        private RandomWordChooser _chooser;
        private XElement _wordXml;
        private readonly string wordsList = "<words><word>Phoenix</word><word>Tucson</word><word>Flagstaff</word><word>Sedona</word></words>";

        [SetUp]
        public void Setup()
        {
            _chooser = new RandomWordChooser();
            _wordXml = XElement.Parse(wordsList);
        }

        [Test]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestGetWordWithoutInjection()
        {
            _chooser.GetRandomWord();
        }

        [Test]
        public void TestGetRandomWord()
        {
            _chooser.WordsXml = _wordXml;
            Assert.IsTrue(_chooser.GetRandomWord() != string.Empty);
            Assert.IsNotNull(_chooser.WordsXml);
        }

        [Test]
        public void TestGetFourNonDuplicateRandomWords()
        {
            List<string> randomWords = new List<string>();
            _chooser.WordsXml = _wordXml;
            for (int index = 0; index <= 3; index++)
            {
                string word = _chooser.GetRandomWord();
                Assert.IsFalse(randomWords.Contains(word));
                randomWords.Add(word);
            }

        }

        [Test]
        public void TestWordsAllUsed()
        {
            TestGetFourNonDuplicateRandomWords();
            _chooser.GetRandomWord();


        }
    }
}
